<?php

namespace app\enterprise\model\department;

use app\model\TimeModel;

class Department extends TimeModel
{
    protected $table = 'sj_deparment';


    public static function getList($where)
    {
        $list = (new self)->where('status', '>', '0')->where($where)
            ->order(['sort' => 'asc', 'create_time' => 'desc'])
            ->select()->toArray();
        return $list;
    }

    public static function getAlllist($where): array
    {
        return (new self)->where('status', '>', '0')
            ->where($where)
            ->order(['pid' => 'asc','sort' => 'asc', 'create_time' => 'desc'])
            ->select()->toArray();
    }
    /**
     * 新增记录
     */
    public function add($data)
    {
        return self::create($data);
    }


    /**
     * 编辑记录
     */
    public function edit($data)
    {
        return self::update($data, ['id' => $data['id'], 'company_id' => $data['company_id']]);
    }

    /**
     * 软删除
     */
    public function setDelete($where)
    {
        return self::update(['status' => -1], $where);
    }
}